package inventory.controller;

import inventory.common.CommonConstants;
import inventory.common.ResultData;
import inventory.entity.Notice;
import inventory.entity.NoticeExample;
import inventory.entity.Repository;
import inventory.entity.po.ReparationPo;
import inventory.mapper.NoticeMapper;
import inventory.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author RenHaiquan
 * @create 2019-10-24 23:31
 */
@RestController
@RequestMapping(CommonConstants.API_VERSION+"/feedback")
public class FeedbackController {
    @Autowired
    FeedbackService feedbackService;

    /**
     * 前端传入上传者名字launcher，公告内容noticeContext
     * 上传公告
     * @return
     */
    @RequestMapping(value = "/addNotice",params = {"launcher","noticeContext"})
    public ResultData addNotice(String launcher,String noticeContext){
        feedbackService.addNotice(launcher,noticeContext);
//        NoticeExample noticeExample = new NoticeExample();
//        NoticeExample.Criteria criteria = noticeExample.createCriteria();
//        criteria.andLauncherEqualTo("2");
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//        Date parse = simpleDateFormat.parse("2019-10-25 17:06:03");
//        criteria.andLaunchTimeEqualTo(parse);
//        List<Notice> notices = noticeMapper.selectByExample(noticeExample);
//        for (Notice A: notices) {
//            System.out.println(A);
//        }
        return new ResultData().OK();
    }
    /**
     * 前端传入公告id noticeId
     * 删除公告
     * @return
     */
    @RequestMapping(value = "/deleteNoticeById",params = {"noticeId"})
    public ResultData deleteNoticeById(String noticeId){
        feedbackService.deleteNoticeById(noticeId);
        return new ResultData().OK();
    }

    /**
     * 前端传入 报修设备串号deviceImei 报修信息描述reparationTaking
     *
     * 报修者reparationerId 报修指向reparationPointer 处理进度handleProgress
     * 新增保修
     * @return
     */
    @RequestMapping(value = "/addRepair",params = {"deviceImei","reparationTaking","reparationerId","reparationPointer","handleProgress"})
    public ResultData addRepair(ReparationPo reparationPo){
        reparationPo.setReparationId(UUID.randomUUID().toString().replace("-",""));

        feedbackService.insert(reparationPo);

        return new ResultData().OK();
    }

    /**
     * 前端传入 保修id reparationId
     * 删除保修
     *
     *
     *
     * @return
     */
        @RequestMapping("/deleteRepairById")
    public ResultData deleteRepairById(String reparationId){
        System.out.println(reparationId);
        int i = feedbackService.deleteReparationPo(reparationId);
        System.out.println(i);
        return new ResultData().OK();
    }

    /**
     * 前端传入 用户id reparationerId
     * 查看用户的所有保修
     * @return
     */
    @RequestMapping("/queryRepairByUserId")
    public ResultData queryRepairByUserId(String reparationerId){
//        System.out.println("kao");
//        System.out.println(reparationerId);
        List<ReparationPo> reparationPos = feedbackService.selectReparationer(reparationerId);
        for(ReparationPo rp:reparationPos){
            System.out.println(rp);
        }
        return new ResultData();

    }

    /**
     * 前端传入 保修id reparationId 进度handleProgress
     * 处理保修
     * @return
     */
    @RequestMapping("/handleRepairById")
    public ResultData handleRepairById(String reparationId,String handleProgress){
        System.out.println(handleProgress);
        int i = feedbackService.updateReparationPo(reparationId,handleProgress);
        return new ResultData();
    }
}
